public class 最大子数组和 {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n + 1];
        int ans = Integer.MIN_VALUE;
        for(int i = 1;i <= n;i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i - 1],nums[i - 1]);
            ans = Math.max(ans,dp[i]);
        }
        return ans;
    }
}
